package nz.co.doherty.gwtpbreadcrumbs.client.ui.customers;

import nz.co.doherty.gwtpbreadcrumbs.client.NameTokens;
import nz.co.doherty.gwtpbreadcrumbs.client.ui.common.ListItemPresenter;
import nz.co.doherty.gwtpbreadcrumbs.shared.entity.Customer;

import com.google.inject.Inject;
import com.philbeaudoin.gwtp.mvp.client.EventBus;
import com.philbeaudoin.gwtp.mvp.client.proxy.PlaceManager;
import com.philbeaudoin.gwtp.mvp.client.proxy.PlaceRequest;

public class CustomerListItemPresenter
		extends ListItemPresenter<Customer, CustomerListItemView> {

	private final PlaceManager placeManager;

	@Inject
	public CustomerListItemPresenter(EventBus eventBus,
			CustomerListItemView view, PlaceManager placeManager) {
		super(eventBus, view);
		this.placeManager = placeManager;
	}

	@Override
	public void init(Customer customer) {
		super.init(customer);
		this.view.setFirstName(customer.getFirstName());
		this.view.setLastName(customer.getLastName());
		this.view.setToken(
			placeManager.buildRelativeHistoryToken(new PlaceRequest(NameTokens.customerView).with(
				"id", Long.toString(customer.getId()))));
	}
}
